using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Gospel.DB
{
	/// <summary>
	/// Strongly-typed collection for the ArticleAttachment class.
	/// </summary>
	[Serializable]
	public partial class ArticleAttachmentCollection : ActiveList<ArticleAttachment, ArticleAttachmentCollection> 
	{	   
		public ArticleAttachmentCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the vbsa_article_attachments table.
	/// </summary>
	[Serializable]
	public partial class ArticleAttachment : ActiveRecord<ArticleAttachment>
	{
		#region .ctors and Default Settings
		
		public ArticleAttachment()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public ArticleAttachment(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public ArticleAttachment(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public ArticleAttachment(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("vbsa_article_attachments", TableType.Table, DataService.GetInstance("VBSA"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarAttId = new TableSchema.TableColumn(schema);
				colvarAttId.ColumnName = "att_id";
				colvarAttId.DataType = DbType.Int32;
				colvarAttId.MaxLength = 0;
				colvarAttId.AutoIncrement = true;
				colvarAttId.IsNullable = false;
				colvarAttId.IsPrimaryKey = true;
				colvarAttId.IsForeignKey = false;
				colvarAttId.IsReadOnly = false;
				colvarAttId.DefaultSetting = @"";
				colvarAttId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAttId);
				
				TableSchema.TableColumn colvarArticleId = new TableSchema.TableColumn(schema);
				colvarArticleId.ColumnName = "article_id";
				colvarArticleId.DataType = DbType.Int32;
				colvarArticleId.MaxLength = 0;
				colvarArticleId.AutoIncrement = false;
				colvarArticleId.IsNullable = false;
				colvarArticleId.IsPrimaryKey = false;
				colvarArticleId.IsForeignKey = true;
				colvarArticleId.IsReadOnly = false;
				colvarArticleId.DefaultSetting = @"";
				
					colvarArticleId.ForeignKeyTableName = "vbsa_articles";
				schema.Columns.Add(colvarArticleId);
				
				TableSchema.TableColumn colvarAttachmentPath = new TableSchema.TableColumn(schema);
				colvarAttachmentPath.ColumnName = "attachment_path";
				colvarAttachmentPath.DataType = DbType.String;
				colvarAttachmentPath.MaxLength = 100;
				colvarAttachmentPath.AutoIncrement = false;
				colvarAttachmentPath.IsNullable = false;
				colvarAttachmentPath.IsPrimaryKey = false;
				colvarAttachmentPath.IsForeignKey = false;
				colvarAttachmentPath.IsReadOnly = false;
				colvarAttachmentPath.DefaultSetting = @"";
				colvarAttachmentPath.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAttachmentPath);
				
				TableSchema.TableColumn colvarCreated = new TableSchema.TableColumn(schema);
				colvarCreated.ColumnName = "created";
				colvarCreated.DataType = DbType.DateTime;
				colvarCreated.MaxLength = 0;
				colvarCreated.AutoIncrement = false;
				colvarCreated.IsNullable = false;
				colvarCreated.IsPrimaryKey = false;
				colvarCreated.IsForeignKey = false;
				colvarCreated.IsReadOnly = false;
				
						colvarCreated.DefaultSetting = @"(getdate())";
				colvarCreated.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreated);
				
				TableSchema.TableColumn colvarAttachmentSize = new TableSchema.TableColumn(schema);
				colvarAttachmentSize.ColumnName = "attachment_size";
				colvarAttachmentSize.DataType = DbType.Int32;
				colvarAttachmentSize.MaxLength = 0;
				colvarAttachmentSize.AutoIncrement = false;
				colvarAttachmentSize.IsNullable = false;
				colvarAttachmentSize.IsPrimaryKey = false;
				colvarAttachmentSize.IsForeignKey = false;
				colvarAttachmentSize.IsReadOnly = false;
				
						colvarAttachmentSize.DefaultSetting = @"((1))";
				colvarAttachmentSize.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAttachmentSize);
				
				TableSchema.TableColumn colvarAttachmentNameTw = new TableSchema.TableColumn(schema);
				colvarAttachmentNameTw.ColumnName = "attachment_name_tw";
				colvarAttachmentNameTw.DataType = DbType.String;
				colvarAttachmentNameTw.MaxLength = 50;
				colvarAttachmentNameTw.AutoIncrement = false;
				colvarAttachmentNameTw.IsNullable = false;
				colvarAttachmentNameTw.IsPrimaryKey = false;
				colvarAttachmentNameTw.IsForeignKey = false;
				colvarAttachmentNameTw.IsReadOnly = false;
				
						colvarAttachmentNameTw.DefaultSetting = @"('')";
				colvarAttachmentNameTw.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAttachmentNameTw);
				
				TableSchema.TableColumn colvarAttachmentNameCn = new TableSchema.TableColumn(schema);
				colvarAttachmentNameCn.ColumnName = "attachment_name_cn";
				colvarAttachmentNameCn.DataType = DbType.String;
				colvarAttachmentNameCn.MaxLength = 50;
				colvarAttachmentNameCn.AutoIncrement = false;
				colvarAttachmentNameCn.IsNullable = false;
				colvarAttachmentNameCn.IsPrimaryKey = false;
				colvarAttachmentNameCn.IsForeignKey = false;
				colvarAttachmentNameCn.IsReadOnly = false;
				
						colvarAttachmentNameCn.DefaultSetting = @"('')";
				colvarAttachmentNameCn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAttachmentNameCn);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["VBSA"].AddSchema("vbsa_article_attachments",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("AttId")]
		public int AttId 
		{
			get { return GetColumnValue<int>("att_id"); }

			set { SetColumnValue("att_id", value); }

		}

		  
		[XmlAttribute("ArticleId")]
		public int ArticleId 
		{
			get { return GetColumnValue<int>("article_id"); }

			set { SetColumnValue("article_id", value); }

		}

		  
		[XmlAttribute("AttachmentPath")]
		public string AttachmentPath 
		{
			get { return GetColumnValue<string>("attachment_path"); }

			set { SetColumnValue("attachment_path", value); }

		}

		  
		[XmlAttribute("Created")]
		public DateTime Created 
		{
			get { return GetColumnValue<DateTime>("created"); }

			set { SetColumnValue("created", value); }

		}

		  
		[XmlAttribute("AttachmentSize")]
		public int AttachmentSize 
		{
			get { return GetColumnValue<int>("attachment_size"); }

			set { SetColumnValue("attachment_size", value); }

		}

		  
		[XmlAttribute("AttachmentNameTw")]
		public string AttachmentNameTw 
		{
			get { return GetColumnValue<string>("attachment_name_tw"); }

			set { SetColumnValue("attachment_name_tw", value); }

		}

		  
		[XmlAttribute("AttachmentNameCn")]
		public string AttachmentNameCn 
		{
			get { return GetColumnValue<string>("attachment_name_cn"); }

			set { SetColumnValue("attachment_name_cn", value); }

		}

		
		#endregion
		
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a Article ActiveRecord object related to this ArticleAttachment
		/// 
		/// </summary>
		public Gospel.DB.Article Article
		{
			get { return Gospel.DB.Article.FetchByID(this.ArticleId); }

			set { SetColumnValue("article_id", value.ArticleId); }

		}

		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int varArticleId,string varAttachmentPath,DateTime varCreated,int varAttachmentSize,string varAttachmentNameTw,string varAttachmentNameCn)
		{
			ArticleAttachment item = new ArticleAttachment();
			
			item.ArticleId = varArticleId;
			
			item.AttachmentPath = varAttachmentPath;
			
			item.Created = varCreated;
			
			item.AttachmentSize = varAttachmentSize;
			
			item.AttachmentNameTw = varAttachmentNameTw;
			
			item.AttachmentNameCn = varAttachmentNameCn;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varAttId,int varArticleId,string varAttachmentPath,DateTime varCreated,int varAttachmentSize,string varAttachmentNameTw,string varAttachmentNameCn)
		{
			ArticleAttachment item = new ArticleAttachment();
			
				item.AttId = varAttId;
				
				item.ArticleId = varArticleId;
				
				item.AttachmentPath = varAttachmentPath;
				
				item.Created = varCreated;
				
				item.AttachmentSize = varAttachmentSize;
				
				item.AttachmentNameTw = varAttachmentNameTw;
				
				item.AttachmentNameCn = varAttachmentNameCn;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string AttId = @"att_id";
			 public static string ArticleId = @"article_id";
			 public static string AttachmentPath = @"attachment_path";
			 public static string Created = @"created";
			 public static string AttachmentSize = @"attachment_size";
			 public static string AttachmentNameTw = @"attachment_name_tw";
			 public static string AttachmentNameCn = @"attachment_name_cn";
						
		}

		#endregion
	}

}

